package jmine.tec.hydra.pack;

import jmine.tec.database.pack.populator.AbstractPopulatorDataSource;
import jmine.tec.database.pack.populator.PopulatorBean;
import jmine.tec.hydra.dao.HydraSystemDAO;
import jmine.tec.hydra.domain.HydraSystem;
import jmine.tec.utils.collection.Mapper;
import jmine.tec.utils.collection.MapperUtils;

/**
 * Populator Data Source que garante o empacotamento dos sistemas descritos no Hydra.
 * 
 * @author lundberg
 */
public class HydraPopulatorDataSource extends AbstractPopulatorDataSource<HydraSystem> {

    private HydraSystemDAO hydraSystemDAO;

    /**
     * {@inheritDoc}
     */
    public Iterable<PopulatorBean<HydraSystem>> load() {
        return MapperUtils.mapList(this.hydraSystemDAO.findAllOrderedByPk(), new Mapper<HydraSystem, PopulatorBean<HydraSystem>>() {
            public PopulatorBean<HydraSystem> apply(HydraSystem input) {
                return new PopulatorBean<HydraSystem>(input, "hydra", input.getMnemonico().toLowerCase() + ".xml");
            }
        });
    }

    /**
     * @param hydraSystemDAO the hydraSystemDAO to set
     */
    public void setHydraSystemDAO(HydraSystemDAO hydraSystemDAO) {
        this.hydraSystemDAO = hydraSystemDAO;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return "HydraPopulatorDataSource";
    }
}
